package com.alit.face.koala.controller;

import java.util.Map.Entry;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alit.face.koala.service.FaceKoalaService;

/**
 * @author litong
 * @date 2019年6月13日_下午9:21:24
 * @version 1.0
 * @desc
 */
@RestController
@RequestMapping("koala_cookie")
public class KoalaHostCookie {
  @Autowired
  private FaceKoalaService ks;

  @RequestMapping("list")
  public String list() {
    JSONArray rows = new JSONArray();
    Set<Entry<String, String>> entrySet = ks.cookiesMap.entrySet();
    for (Entry<String, String> e : entrySet) {
      JSONObject row = new JSONObject();
      row.put("ip", e.getKey());
      row.put("cookie", e.getValue());
      rows.add(row);
    }
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("total", ks.cookiesMap.size());
    jsonObject.put("rows", rows);
    return jsonObject.toJSONString();
  }
}
